<?php
namespace jy_yzwd;
defined('BY_JYA') or exit('error');
/*
	有赞接口
	
*/
require_once ROOT_D.'/addons/jy_yzwd/open-sdk-php/lib/YZTokenClient.php';
//请填入商家授权后获取的access_token

class func extends \plugin{
	function get_token(){
		$setting=$this->plugin_setting('basic');
		if(!$setting['client_id']){
			exi('请先配置接口参数！','error','jy_yzwd/index/');
		}
		$res = model('core/http')->ihttp_request("https://open.youzan.com/oauth/token?client_id={$setting['client_id']}&client_secret={$setting['client_secret']}&grant_type=silent&kdt_id={$setting['kdt_id']}");
		$res = json_decode($res['content'],true);
		print_r($res);
		$token = $res['access_token'];
		return $token;
	}
	function getList(){
		$token = $this->get_token();
		
		$client = new \YZTokenClient($token);

		$method = 'youzan.items.onsale.get'; //要调用的api名称
		$api_version = '3.0.0'; //要调用的api版本号

		$my_params = [
			'order_by' => 'sold_num',
			'page_no' => '1',
			'page_size' => '10',
		];

		$my_files = [
		];
		$res = $client->post($method, $api_version, $my_params, $my_files);
		$data = $res['response']['items'];
		return $data;
	}
	function getOrders(){
		$setting=$this->plugin_setting('basic');
		$token = $this->get_token();//请填入商家授权后获取的access_token
		$client = new \YZTokenClient($token);

		$method = 'youzan.trades.sold.get'; //要调用的api名称
		$api_version = '4.0.0'; //要调用的api版本号

		$my_params = [
			'offline_id' => $setting['kdt_id'],
		];

		$my_files = [
		];
		$res=$client->get($method, $api_version, $my_params, $my_files);
		$data=$res['full_order_info_list']['full_order_info'];
		return $data;
	}



}